/**
 * Company : TIS.
 * Created By : Chatree Siangklom
 * Created On : Jul 17, 2013  1:45:43 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.interfaces.controller.home
 * File Name : HomeController.java
 * TODO
 */
package com.tis.interfaces.controller.home;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.tis.interfaces.controller.commons.CommonController;
import com.tis.interfaces.controller.login.LoginController;

/**
 * @author chatree
 *
 */
@Controller
public class HomeController extends CommonController{
	
	private static final Logger log = LoggerFactory.getLogger(HomeController.class);
		
	@RequestMapping(value="/", method = RequestMethod.GET)
	public String mainPage(HttpServletRequest request)  throws Exception {
		log.info("welcome to mainPage");
		setCurrentAppsInstanceNo();
		
		//Put History 		
		try { UserAccessTime(request, this.toString()); }catch(Exception e) {e.printStackTrace();}
		
		if(!UserLoginValidation(request))
			return "redirect:/login.htm";
		
		return "/home/mainpage";
	}

	@RequestMapping(value="/index", method = RequestMethod.GET)
	public String indexPage(HttpServletRequest request) throws Exception {
		log.info("welcome to indexPage {index}");
		setCurrentAppsInstanceNo();
		
		//Put History 		
		try { UserAccessTime(request, this.toString()); }catch(Exception e) {e.printStackTrace();}

		if(!UserLoginValidation(request))
			return "redirect:/login.htm";
		
		return "/home/mainpage";
	}
}
